// 获取当前日期 2023-01-01
const getDate = () => {
  let date = new Date();
  let year = date.getFullYear(); 
  let month = date.getMonth() + 1;
  let day = date.getDate();
  month = (month > 9) ? month : ("0" + month);
  day = (day < 10) ? ("0" + day) : day;
  let today = year + "-" + month + "-" + day;
  return today
}

// 计算日期 2023-01-01 to 2023 January 1st
const en_mounth = ["January","February","March","April","May","June","July","August","September","October","November","December"];
const dateDisplay = (date) => {
  let year = date.split('-')[0];
  let mounth = en_mounth[date.split('-')[1] - 1];
  let day = Number(date.split('-')[2]);
  switch (day%10) {
    case 1:
      day = day + 'st';
      break;
    case 2:
      day = day + 'nd';
      break;
    case 3:
      day = day + 'rd';
      break;
    default:
      day = day + 'th';
      break;
  }
  return year + ' ' + mounth + ' ' + day
}

// 计算月份 2023-01-xx to January 2023
const mounthDisplay = (date) => {
  let year = date.split('-')[0];
  let mounth = en_mounth[date.split('-')[1] - 1];
  return mounth + '' + year
}

// 获取当前精确时间
const getCurrentTime = () => {
  let time = new Date()
  return getDate() + ' ' + time.toLocaleTimeString()
}
export { getDate, dateDisplay, mounthDisplay, getCurrentTime }